const secretkey = '🎆🎍jkeof9'

import CryptoJS from 'crypto-js'

/**
 * @description: 本地数据加密存储
 * @param {*} key：加密的键
 * @param {*} value：加密的值
 */
export function setEncryptedData(key, value) {
    if (typeof value === 'object') {
        value = JSON.stringify(value)
    }
    localStorage.setItem(key, CryptoJS.AES.encrypt(value, secretkey).toString())
}

/**
 * @description: 本地数据解密
 * @param {*} key：获取本地数据的键
 */
export  function getEncryptedData(key) {
    const cipherText = localStorage.getItem(key)
    if (!cipherText) return {}
    const a =   CryptoJS.AES.decrypt(cipherText, secretkey)
    const _formData = a.toString(CryptoJS.enc.Utf8)
    
    return JSON.parse(_formData)
}